SHELL=/usr/bin/env bash

all: build
.PHONY: all

unexport GOFLAGS

GOCC?=go

GOVERSION:=$(shell $(GOCC) version | tr ' ' '\n' | grep go1 | sed 's/^go//' | awk -F. '{printf "%d%03d%03d", $$1, $$2, $$3}')
ifeq ($(shell expr $(GOVERSION) \< 1016000), 1)
	$(warning Your Golang version is go$(shell expr $(GOVERSION) / 1000000).$(shell expr $(GOVERSION) % 1000000 / 1000).$(shell expr $(GOVERSION) % 1000))
	$(error Update Golang to version to at least 1.16.0)
endif

# git modules that need to be loaded
MODULES:=

CLEAN:=
BINS:=

#ldflags=-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.$(subst -,.,$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null))
#ldflags=-X=gitee.com/jacky6666/rabbit-im/server/build.CurrentCommit=+git.$(subst -,.,$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null))
ifneq ($(strip $(LDFLAGS)),)
	ldflags+=-extldflags=$(LDFLAGS)
endif
GOFLAGS+=-ldflags="$(ldflags)"

rabbit-file: $(BUILD_DEPS)
	rm -f rabbit-file
	$(GOCC) build $(GOFLAGS) -o rabbit-file ./cmd/rabbit_file
.PHONY: rabbit-file
BINS+=rabbit-file

rabbit-im: $(BUILD_DEPS)
	rm -f rabbit-im
	$(GOCC) build $(GOFLAGS) -o rabbit-im ./cmd/rabbit_im
.PHONY: rabbit-im
BINS+=rabbit-im

rabbit-login: $(BUILD_DEPS)
	rm -f rabbit-login
	$(GOCC) build $(GOFLAGS) -o rabbit-login ./cmd/rabbit_login
.PHONY: rabbit-login
BINS+=rabbit-login

rabbit-pusher: $(BUILD_DEPS)
	rm -f rabbit-pusher
	$(GOCC) build $(GOFLAGS) -o rabbit-pusher ./cmd/rabbit_pusher
.PHONY: rabbit-pusher
BINS+=rabbit-pusher

.PHONY: deps
deps:
	#go mod vendor
	go mod tidy

all: $(BINS)
.PHONY: all

clean:
	rm -rf $(CLEAN) $(BINS)
.PHONY: clean


dist-clean:
	git clean -xdff
	git submodule deinit --all -f
.PHONY: dist-clean

